# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pygtk

pkgname="${MINGW_PACKAGE_PREFIX}-python2-pygtk"
pkgver=2.24.0
pkgrel=2
pkgdesc="Python bindings for the GTK widget set (mingw-w64)"
arch=(any)
url="http://www.pygtk.org"
license=('LGPL')
groups=("${MINGW_PACKAGE_PREFIX}")
depends=("${MINGW_PACKAGE_PREFIX}-python2-cairo"
    "${MINGW_PACKAGE_PREFIX}-python2-gobject2"
    "${MINGW_PACKAGE_PREFIX}-libglade")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-numpy")
options=('staticlibs' 'strip')
source=(http://ftp.gnome.org/pub/gnome/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.bz2
    python27.patch
    no-undefined.patch
    python-m4.patch)
md5sums=('a1051d5794fd7696d3c1af6422d17a49'
         '12acfacd26f19c504a0a2d0edeb66121'
         'edd96a4d9f4b7a1b05094a78f9cc811b'
         '2f1b6f04e36474e58abb259e22cc8309')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/python27.patch
  patch -p1 -i ${srcdir}/no-undefined.patch
  patch -p1 -i ${srcdir}/python-m4.patch
  autoreconf -fi -I m4
  #WANT_AUTOMAKE=latest ./autogen.sh
}

build() {
  cd "$srcdir"

  rm -rf python2-build
  mkdir python2-build
  #cp -r ${_realname}-$pkgver $builddir
  pushd python2-build
    PYTHON=${MINGW_PREFIX}/bin/python2 \
    ../${_realname}-$pkgver/configure --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}
    make VERBOSE=1
  popd
}

package() {
  cd python2-build
  make DESTDIR="$pkgdir" install
  install -m644 ${srcdir}/${_realname}-$pkgver/gtk/gtk-extrafuncs.defs "${pkgdir}${MINGW_PREFIX}/share/pygtk/2.0/defs/"
  sed -i -e 's#env python$#env python2#' "${pkgdir}${MINGW_PREFIX}"/lib/pygtk/2.0/{,demos/}*.py
}
